<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>Inscription</title>
        <meta name="keywords" content="" />
        <meta name="description" content="" />
        <link rel="stylesheet" type="text/css" href="default.css" />
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" src="scripts.js"></script>

    </head>
    <body>
        <div id="upbg"></div>
        <div id="outer">

            <?php
            include 'header.php';
            ?>
            <?php
            include 'login.php';
            include 'menu.php';
            ?>
            <div id="content">

                <?php
                if (isset($_POST["inscription"]) == "ok") {
                    //On test si tout les champs ont bien été remplis.
                    if (!empty($_POST["log"]) && !empty($_POST["pass"]) &&
                            !empty($_POST["nom"]) && !empty($_POST["prenom"]) &&
                            !empty($_POST["mail"]) && !empty($_POST["datenaiss"])) {
                        include 'utils/verificateurDate.class.php';
                        $verifDate = new verificateurDate($_POST["datenaiss"]);
                        if ($verifDate->estValide(false)) {
                            $dateString = $verifDate->getDateCompatibleBDD();

                            $query = " insert into User(login,password,first_name, last_name, birthdate, mail) 
                            values ('" . addslashes($_POST['log']) . "', '" . md5($_POST['pass']) . "',
                                '" . addslashes($_POST['prenom']) . "', '" . addslashes($_POST['nom']) . "',
                                    '$dateString', '" . addslashes($_POST['mail']) . "')";
                            //requete qui insert l'ensemble des champs dans la base de données
                            mysql_query($query) or die(mysql_error());
                            echo "<div style='color:green;'>Inscription reussie</div>";
                        }else{
                            echo "<div style='color:red;'>Date invalide</div>";
                        }
                        }else
                            echo "<div style='color:red;'>Veuillez renseigner tous les champs.</div>";
                    }
                    ?>
                    <div id='blockInscription'>
                        <div class='sousTitreInfoInscription'>S'inscrire</div>
                        <form action="creationCompte.php" method="post"><p>
                                <label for="login">Login :</label><input type="text" name="log" value="" id="inputLogin"/><br />
                                <label for='prenom'>Prénom : </label><input type='text' name='prenom' value='' id='inputPrenom'/><br />
                                <label for='nom'>Nom : </label><input type='text' name='nom' value='' id='inputNom'/><br />
                                <label for='mail'>Mail : </label><input type='text' name='mail' value='' id='inputMail'/><br />
                                <label for="password">Nouveau mot de passe :</label><input type="password" name="pass" value="" id="password"/><br />
                                <label for='datenaiss'>Date de naissance : </label><input type='text' name='datenaiss' value='' id='inputDateNaiss'/><br />
                                <label for="cache"> </label>	<input type="hidden" name="inscription" value="ok"/>
                                <div>
                                    <input type="submit" value="Inscription" name="bouton" id="submitInscription"/>
                                </div>
                            </p></form>
                    </div>

                </div>

                <?php
                include 'footer.php';
                ?>

    </body>
</html>

